#include "AddBlockToRowNetworkEvent.h"
#include "Row.h"

AddBlockToRowNetworkEvent::AddBlockToRowNetworkEvent(long rowId, const Position& position, const Color& color)
{
    message.header.code = NetworkEvent::SERVER_ADD_BLOCK_TO_ROW;
    message.header.sizeOfData = sizeof(message) - sizeof(message.header);
    message.data.rowId = rowId;
    message.data.x = position.x;
    message.data.y = position.y;
    message.data.colorR = color.r;
    message.data.colorG = color.g;
    message.data.colorB = color.b;
}

AddBlockToRowNetworkEvent::AddBlockToRowNetworkEvent(const Header& header, const Data& data)
{
    message.header = header;
    message.data = data;
}

AddBlockToRowNetworkEvent::~AddBlockToRowNetworkEvent()
{
}

void* AddBlockToRowNetworkEvent::getMessageBlob()
{
    return &message;
}

size_t AddBlockToRowNetworkEvent::getMessageBlobSize()
{
    return sizeof(message);
}

void AddBlockToRowNetworkEvent::visitRow(Row* row) const
{
    row->handleAddBlockToRowEvent(message.data.rowId, Position(message.data.x, message.data.y),
            Color(message.data.colorR, message.data.colorG, message.data.colorB));
}

